home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / CustomSolutionWizard_Files / ProjectShells / NSNetwork.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  11.3 KB  |  219 lines

  1. //===========================================================================
  2. // Custom Solution Wizard - NSNetwork Class Definition
  3. //
  4. // Copyright (c) 2000 - NeuroDimension, Inc.
  5. //---------------------------------------------------------------------------
  6. // This file is provided to demonstrate how classes can be constructed to
  7. // encapsulate the functions in a Custom Solution Wizard generated DLL.
  8. // The classes in this file can be used without modication, but are not
  9. // required for interaction with generated DLLs.
  10. //---------------------------------------------------------------------------
  11. // Three sample classes are provided:
  12. //
  13. //        NSNetwork            Common parent to NSLearningNetwork and NSRecallNetwork.
  14. //        NSLearningNetwork    Encapsulation of LEARNING DLL.
  15. //        NSRecallNetwork        Encapsulation of RECALL DLL.
  16. //
  17. //===========================================================================
  18.  
  19. //===========================================================================
  20. // Enum: NetworkType
  21. //---------------------------------------------------------------------------
  22. //    This value is used to differentiate between RECALL and LEARNING networks.
  23. //===========================================================================
  24. enum {RECALL, LEARNING};
  25.  
  26. //===========================================================================
  27. // DLL Function TypeDefs
  28. //---------------------------------------------------------------------------
  29. //    These typedefs define the functions and function parameters in the generated DLL.
  30. //===========================================================================
  31.  
  32. // Functions in both RECALL and LEARNING DLLs
  33. typedef int (*NSCreateNetwork)(void *&pNeuralNetwork, int networkType);
  34. typedef int (*NSDestroyNetwork)(void *pNeuralNetwork);
  35. typedef int (*NSGetInputOutputInfo)(void *pNeuralNetwork, int &numInputs, int &numOutputs);
  36. typedef int (*NSGetResponse)(void *pNeuralNetwork, int exemplars, float *inputData, float *outputData);
  37. typedef int (*NSGetSensitivity)(void *pNeuralNetwork, int exemplars, float *inputData, float *&sensitivityData, float dither);
  38. typedef int (*NSLoadWeights)(void *pNeuralNetwork, const char *weightsPathName);
  39. typedef int (*NSSaveWeights)(void *pNeuralNetwork, const char *weightsPathName);
  40. typedef int (*NSRandomizeWeights)(void *pNeuralNetwork);
  41. typedef int (*NSResetNetwork)(void *pNeuralNetwork);
  42.  
  43. // Functions in LEARNING DLLs only
  44. typedef int (*NSTrain)(void *pNeuralNetwork, int epochs, int exemplars, float *inputData, float *desiredData, int cvExemplars, float *cvInputData, float *cvDesiredData);
  45. typedef int (*NSGetBestCost)(void *pNeuralNetwork, float &bestCost);
  46. typedef int (*NSSetBestCost)(void *pNeuralNetwork, float bestCost);
  47. typedef int (*NSGetBestWeightsPathName)(void *pNeuralNetwork, char *bestWeightsPathName, int bufferLength, int &pathNameLength);
  48. typedef int (*NSSetBestWeightsPathName)(void *pNeuralNetwork, const char *bestWeightsPathName);
  49. typedef int (*NSGetSaveBestWeightsEnabled)(void *pNeuralNetwork, bool &saveBestWeightsEnabled);
  50. typedef int (*NSSetSaveBestWeightsEnabled)(void *pNeuralNetwork, bool saveBestWeightsEnabled);
  51. typedef int (*NSGetSaveBestWeightsForTraining)(void *pNeuralNetwork, bool &saveBestWeightsForTraining);
  52. typedef int (*NSSetSaveBestWeightsForTraining)(void *pNeuralNetwork, bool saveBestWeightsForTraining);
  53. typedef int (*NSGetCrossValidationEnabled)(void *pNeuralNetwork, bool &crossValidationEnabled);
  54. typedef int (*NSSetCrossValidationEnabled)(void *pNeuralNetwork, bool crossValidationEnabled);
  55. typedef int (*NSSetAutoComputeInputNormCoeff)(void *pNeuralNetwork, bool autoComputeInputNormCoeff);
  56. typedef int (*NSGetAutoComputeInputNormCoeff)(void *pNeuralNetwork, bool &autoComputeInputNormCoeff);
  57. typedef int (*NSSetAutoComputeOutputNormCoeff)(void *pNeuralNetwork, bool autoComputeOutputNormCoeff);
  58. typedef int (*NSGetAutoComputeOutputNormCoeff)(void *pNeuralNetwork, bool &autoComputeOutputNormCoeff);
  59. typedef int (*NSRemoveInputNormalization)(void *pNeuralNetwork);
  60. typedef int (*NSRemoveOutputNormalization)(void *pNeuralNetwork);
  61. typedef int (*NSSetInputNormMin)(void *pNeuralNetwork, float inputNormMin);
  62. typedef int (*NSGetInputNormMin)(void *pNeuralNetwork, float &inputNormMin);
  63. typedef int (*NSSetInputNormMax)(void *pNeuralNetwork, float inputNormMax);
  64. typedef int (*NSGetInputNormMax)(void *pNeuralNetwork, float &inputNormMax);
  65. typedef int (*NSSetOutputNormMin)(void *pNeuralNetwork, float outputNormMin);
  66. typedef int (*NSGetOutputNormMin)(void *pNeuralNetwork, float &outputNormMin);
  67. typedef int (*NSSetOutputNormMax)(void *pNeuralNetwork, float outputNormMax);
  68. typedef int (*NSGetOutputNormMax)(void *pNeuralNetwork, float &outputNormMax);
  69. typedef int (*NSSetNormalizeInputByChannel)(void *pNeuralNetwork, bool normalizeInputByChannel);
  70. typedef int (*NSGetNormalizeInputByChannel)(void *pNeuralNetwork, bool &normalizeInputByChannel);
  71. typedef int (*NSSetNormalizeOutputByChannel)(void *pNeuralNetwork, bool normalizeOutputByChannel);
  72. typedef int (*NSGetNormalizeOutputByChannel)(void *pNeuralNetwork, bool &normalizeOutputByChannel);
  73. typedef int (*NSGetCrossValidationCostData)(void *pNeuralNetwork, float *CVCostData);
  74. typedef int (*NSGetCostData)(void *pNeuralNetwork, float *costData);
  75. typedef int (*NSGetNumberOfEpochsTrained)(void *pNeuralNetwork, int &numberOfEpochsTrained);
  76. typedef int (*NSGetEpochOfBestCost)(void *pNeuralNetwork, int &epochOfBestCost);
  77. typedef int (*NSSeedRandom)(void *pNeuralNetwork, unsigned int seed);
  78.  
  79.  
  80. //===========================================================================
  81. // CLASS: NSNetwork
  82. //===========================================================================
  83. class NSNetwork
  84. {
  85. public:
  86.     //---------------------------------------------------------------------------
  87.     // Public functions.
  88.     //---------------------------------------------------------------------------
  89.     NSNetwork(LPCSTR dllPathName);
  90.     ~NSNetwork();
  91.  
  92.     bool IsLoaded()            {return (m_hDLL != 0);};
  93.     bool IsInitialized()    {return (IsLoaded() && m_pNetworkInstance);};
  94.  
  95.     int GetInputs();
  96.     int GetOutputs();
  97.     int GetInputOutputInfo(int& numInputs, int& numOutputs);
  98.     int GetResponse(int exemplars, float* inputData, float* outputData);
  99.     int GetSensitivity(int exemplars, float* inputData, float* sensitivityData, float dither);
  100.     int LoadWeights(LPCSTR pathName);
  101.     int RandomizeWeights();
  102.     int ResetNetwork();
  103.     int SaveWeights(LPCSTR pathName);
  104.  
  105. protected:
  106.     //---------------------------------------------------------------------------
  107.     // Protected variables.
  108.     //---------------------------------------------------------------------------
  109.     HINSTANCE m_hDLL;
  110.     void* m_pNetworkInstance;
  111.     NSCreateNetwork m_NSCreateNetwork;
  112.     NSDestroyNetwork m_NSDestroyNetwork;
  113.     NSLoadWeights m_NSLoadWeights;
  114.     NSSaveWeights m_NSSaveWeights;
  115.     NSRandomizeWeights m_NSRandomizeWeights;
  116.     NSResetNetwork m_NSResetNetwork;
  117.     NSGetInputOutputInfo m_NSGetInputOutputInfo;
  118.     NSGetResponse m_NSGetResponse;
  119.     NSGetSensitivity m_NSGetSensitivity;
  120. };
  121.  
  122. //===========================================================================
  123. // CLASS: NSLearningNetwork
  124. //===========================================================================
  125. class NSLearningNetwork : public NSNetwork
  126. {
  127. public:
  128.     //---------------------------------------------------------------------------
  129.     // Public functions.
  130.     //---------------------------------------------------------------------------
  131.     NSLearningNetwork(LPCSTR dllPathName);
  132.  
  133.     int RemoveInputNormalization();
  134.     int RemoveOutputNormalization();
  135.     int SeedRandom(unsigned int seed);
  136.     int Train(int epochs, int exemplars, float* inputData, float* desiredData);
  137.     int Train(int epochs, int exemplars, float* inputData, float* desiredData, int cvExemplars, float* cvInputData, float* cvDesiredData);
  138.     bool GetAutoComputeInputNormCoeff();
  139.     bool GetAutoComputeOutputNormCoeff();
  140.     float GetBestCost();
  141.     CString GetBestWeightsPathName();
  142.     int GetCostData(float *costData);
  143.     int GetCrossValidationCostData(float *CVCostData);
  144.     bool GetCrossValidationEnabled();
  145.     int GetEpochOfBestCost();
  146.     float GetInputNormMax();
  147.     float GetInputNormMin();
  148.     bool GetNormalizeInputByChannel();
  149.     bool GetNormalizeOutputByChannel();
  150.     int GetNumberOfEpochsTrained();
  151.     float GetOutputNormMax();
  152.     float GetOutputNormMin();
  153.     bool GetSaveBestWeightsEnabled();
  154.     bool GetSaveBestWeightsForTraining();
  155.     int SetAutoComputeInputNormCoeff(bool autoComputeInputNormCoeff);
  156.     int SetAutoComputeOutputNormCoeff(bool autoComputeOutputNormCoeff);
  157.     int SetBestCost(float bestCost);
  158.     int SetBestWeightsPathName(LPCSTR pathName);
  159.     int SetCrossValidationEnabled(bool value);
  160.     int SetInputNormMax(float inputNormMax);
  161.     int SetInputNormMin(float inputNormMin);
  162.     int SetNormalizeInputByChannel(bool normalizeInputByChannel);
  163.     int SetNormalizeOutputByChannel(bool normalizeOutputByChannel);
  164.     int SetOutputNormMax(float outputNormMax);
  165.     int SetOutputNormMin(float outputNormMin);
  166.     int SetSaveBestWeightsEnabled(bool value);
  167.     int SetSaveBestWeightsForTraining(bool value);
  168.  
  169. protected:
  170.     //---------------------------------------------------------------------------
  171.     // Protected variables.
  172.     //---------------------------------------------------------------------------
  173.     NSTrain m_NSTrain;
  174.     NSGetBestCost m_NSGetBestCost;
  175.     NSSetBestCost m_NSSetBestCost;
  176.     NSGetBestWeightsPathName m_NSGetBestWeightsPathName;
  177.     NSSetBestWeightsPathName m_NSSetBestWeightsPathName;
  178.     NSGetCrossValidationEnabled m_NSGetCrossValidationEnabled;
  179.     NSSetCrossValidationEnabled m_NSSetCrossValidationEnabled;
  180.     NSGetSaveBestWeightsEnabled m_NSGetSaveBestWeightsEnabled;
  181.     NSSetSaveBestWeightsEnabled m_NSSetSaveBestWeightsEnabled;
  182.     NSGetSaveBestWeightsForTraining m_NSGetSaveBestWeightsForTraining;
  183.     NSSetSaveBestWeightsForTraining m_NSSetSaveBestWeightsForTraining;
  184.     NSSetAutoComputeInputNormCoeff m_NSSetAutoComputeInputNormCoeff;
  185.     NSGetAutoComputeInputNormCoeff m_NSGetAutoComputeInputNormCoeff;
  186.     NSSetAutoComputeOutputNormCoeff m_NSSetAutoComputeOutputNormCoeff;
  187.     NSGetAutoComputeOutputNormCoeff m_NSGetAutoComputeOutputNormCoeff;
  188.     NSRemoveInputNormalization m_NSRemoveInputNormalization;
  189.     NSRemoveOutputNormalization m_NSRemoveOutputNormalization;
  190.     NSSetInputNormMin m_NSSetInputNormMin;
  191.     NSGetInputNormMin m_NSGetInputNormMin;
  192.     NSSetInputNormMax m_NSSetInputNormMax;
  193.     NSGetInputNormMax m_NSGetInputNormMax;
  194.     NSSetOutputNormMin m_NSSetOutputNormMin;
  195.     NSGetOutputNormMin m_NSGetOutputNormMin;
  196.     NSSetOutputNormMax m_NSSetOutputNormMax;
  197.     NSGetOutputNormMax m_NSGetOutputNormMax;
  198.     NSSetNormalizeInputByChannel m_NSSetNormalizeInputByChannel;
  199.     NSGetNormalizeInputByChannel m_NSGetNormalizeInputByChannel;
  200.     NSSetNormalizeOutputByChannel m_NSSetNormalizeOutputByChannel;
  201.     NSGetNormalizeOutputByChannel m_NSGetNormalizeOutputByChannel;
  202.     NSGetCrossValidationCostData m_NSGetCrossValidationCostData;
  203.     NSGetCostData m_NSGetCostData;
  204.     NSGetNumberOfEpochsTrained m_NSGetNumberOfEpochsTrained;
  205.     NSGetEpochOfBestCost m_NSGetEpochOfBestCost;
  206.     NSSeedRandom m_NSSeedRandom;
  207. };
  208.  
  209. //===========================================================================
  210. // CLASS: NSRecallNetwork
  211. //===========================================================================
  212. class NSRecallNetwork : public NSNetwork
  213. {
  214. public:
  215.     //---------------------------------------------------------------------------
  216.     // Public functions.
  217.     //---------------------------------------------------------------------------
  218.     NSRecallNetwork(LPCSTR dllPathName);
  219. };